<?php
if(isset($_POST['submit']))
{
	$account = $_POST['account'];
	$passwordOld = $_POST['passwordOld'];
	$passwordNew = $_POST['passwordNew'];
	$passwordNew1 = $_POST['passwordNew1'];
include_once "configp.php";
	$con = mysql_connect($dbhost.":".$dbport, $dbuser, $dbpass) or die(mysql_error());
	mysql_select_db($dbwname) or die(mysql_error());

	$account = mysql_real_escape_string($account);
	$passwordOld = mysql_real_escape_string($passwordOld);
	$passwordNew = mysql_real_escape_string($passwordNew);
	$passwordNew1 = mysql_real_escape_string($passwordNew1);

	$textcolor = "FFFFFF";

	$query = "SELECT acct FROM accounts WHERE login = '".$account."' AND password = '".$passwordOld."'";

	$result = mysql_query($query) or die(mysql_error());
	$numrows = mysql_num_rows($result);

	echo "<tr><td align=center>";

	//if no rows exist, the character does not exist
	if($passwordNew != $passwordNew1)
	{
		die("New password fields must match!");
	}
	if($numrows == 0)
	{
		die("Invalid account name/password!");
	}

	$query = "UPDATE accounts SET password = '".$passwordNew."' WHERE login = '".$account."'";
	$result = mysql_query($query) or die(mysql_error());

	echo "<center>";
	echo "<br />";
	echo "<br />";
	echo "Password for the Account '<b>".$account."</b>' has been successfully changed!<br />";
	echo "<a href='javascript:history.go(-1)'>Back</a>";

	echo "</td></tr>";

	//close mysql connection
	mysql_close();
}
//if page is loaded, display unstuck form
else
{
	echo "<form name=myform method=post action='./passchange.php'>";

	echo "<br />";
	echo "<center>";

	echo "<h1><u><b>Password Changer</b></u></h1>";
	echo "<br />";
	echo "<tr><td width=125>Account Name: </td><td><input type=text name=account value=''></td></tr>";
	echo "<br />";
	echo "<tr><td width=125>Old Password: </td><td><input type=password name=passwordOld value=''></td></tr>";
	echo "<br />";
	echo "<tr><td width=125>New Password: </td><td><input type=password name=passwordNew value=''></td></tr>";
	echo "<br />";
	echo "<tr><td width=125>Re-Enter Password: </td><td><input type=password name=passwordNew1 value=''></td></tr>";
	echo "<br />";
	echo "<tr><td colspan=2 align=center><br><input type=submit name=submit value=Submit></td></tr>";
	echo "</form>";
	echo "</center>";
}

	echo "<center>";
	echo "</table>";
	echo "<br />";
	echo "<br />";
	echo "You <b>MUST</b> be offline for this tool to successfully work!<br><br>";
	echo "<br />";
	echo " ";
	echo "<br />";
	echo "</center>";

?>